package mythesis.controller;
import javax.tools.*;
import java.io.*;
import java.util.*;

public class Compiler{
   public String compile()
   {
	   return "WTF";
	   /*
	   try {
	       Process p = Runtime.getRuntime().exec("compiletest.cmd");
	       System.out.println("wat1");
	       p.waitFor();
	       System.out.println("wat2");
	       int result = (p.exitValue());
	       System.out.println("wat");
	       if (result == 0)
	       {
	    	   //System.out.println("Successful compilation.");
	    	   return "Code" + result + ": Successful compilation";
	       }
	       else
	       {
	    	   //System.out.println("Something went wrong with compilation, that wasn't supposed to happen.  Please try manual compilation for details.");
	    	   return "Code" + result + ": Something went wrong with compilation, that wasn't supposed to happen.  Please try manual compilation for details.";
	       }
	       
	   }
	   catch (Exception err) {
		   
	       err.printStackTrace();
	       return "Exception error.";
	   }*/
   }
	
   public static void main(String args[])
   {
      /*
      JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
      
      int compilationResult = compiler.run(null, null, null, "HelloWorld.java");
      if (compilationResult == 0)
      {
         System.out.println("Compilation success.");  
      }
      else
      {
         System.out.println("Compilation failed.");
      }
      
      StandardJavaFileManager manager = compiler.getStandardFileManager(null,null,null);
      URL urls[] = {new URL("file://C:\\Users\\ncinco\\Eclipse\\Workspace\\Compiler\\src\\HelloWorld.java")};
      ClassLoader cl_old = Thread.currentThread().getContextClassLoader();
      ClassLoader cl_new = new URLClassLoader(urls, cl_old);
      //Class compiledClass = cl_new.loadClass("HelloWorld");
      */
      
      //File file = new File("C:/Users/ncinco/Eclipse/workspace/ClueMeRemake/src/mythesis/controller/HelloWorld.java");
      //File file = new File("HelloWorld.java");
      //System.out.println(file.getAbsolutePath()); //C:\Users\ncinco\Eclipse\workspace\ClueMeRemake\HelloWorld.java
      //System.out.println(file.getCanonicalPath());
	   
	   /*
	  File file = new File("C:/Users/ncinco/Eclipse/workspace/Cluedo/Cluedo/AI/CustomAI3.java");
	  System.out.println(file.getAbsolutePath());
      File files1 = file;
      
      JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
      StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
      
      Iterable<? extends JavaFileObject> compilationUnits1 = 
         fileManager.getJavaFileObjectsFromFiles(Arrays.asList(files1));
      boolean result = compiler.getTask(null, fileManager, null, null, null, compilationUnits1).call();
      
      if (result){ System.out.println("Compilation success!"); }
      else       { System.out.println("Compilation failed."); }
      */
	   
	   /*
	   try {
	       Process p = Runtime.getRuntime().exec("compiletest.cmd");
	       p.waitFor();
	       int result = (p.exitValue());
	       if (result == 0)
	       {
	    	   System.out.println("Successful compilation.");
	       }
	       else
	       {
	    	   System.out.println("Something went wrong with compilation, that wasn't supposed to happen.  Please try manual compilation for details.");
	       }
	   }
	   catch (Exception err) {
	       err.printStackTrace();
	   }
	   /*
       try {  
           Process p = Runtime.getRuntime().exec("cmd /C javac -classpath C:/Users/ncinco/Eclipse/workspace/Cluedo C:/Users/ncinco/Eclipse/workspace/Cluedo/Cluedo/AI/HelloWorld.java ");  
           BufferedReader in = new BufferedReader(  
                               new InputStreamReader(p.getInputStream()));  
           String line = null;
           while ((line = in.readLine()) != null) {  
               System.out.println(line);  
           }  
       } catch (IOException e) {  
           e.printStackTrace();  
       } */
	   
	   /*
	   Process p;
	   try{
		   p = Runtime.getRuntime().exec("cmd /C javac -classpath C:/Users/ncinco/Eclipse/workspace/Cluedo C:/Users/ncinco/Eclipse/workspace/Cluedo/Cluedo/AI/HelloWorld.java ");
	   

		   // read the standard output of the command
	
		   BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
	
		   System.out.println("Here is the standard output of the command:\n");
		   int count = 0;
		   String result = "";
		   String s = "";
	      
		   while (!procDone(p)) {
			   try{
				   while((s=stdInput.readLine()) !=null){
		              count++;
		              result = result+s+"\n";
		              System.out.println("result:"+count+": "+result);
				   }
			   }
			   catch(Exception e){ System.err.println(e); }
		   }
		   try{
			   stdInput.close();
		   }catch(Exception e){ System.err.println(e); }
	   }catch(Exception e){ System.err.println(e); }
     }

   private static boolean procDone(Process p) {
	      try {
	          int v = p.exitValue();
	          return true;
	      }
	      catch(IllegalThreadStateException e) {
	          return false;
	      }
	  }*/
	   
   }
}

